package customview.ike.com.customviewproject.widget;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.nfc.Tag;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by Administrator on 2017/12/9.
 */

public class BubbleDrawable extends Drawable {
    private RectF rect;
    private RectF innerRect;
    private String Tag = "BubbleDrawable";
    private Paint borderPaint;
    private Paint innerPaint;
    private int borderWidth = 1;
    float radius = 10.f;
    private Path path = new Path();

    public BubbleDrawable(RectF rect) {
        this.rect = rect;
        this.rect.left += borderWidth;
        this.rect.top += borderWidth + 30;
        this.rect.right -= borderWidth;
        this.rect.bottom -= borderWidth;
        innerRect = this.rect;
        this.innerRect.left += borderWidth;
        this.innerRect.top += borderWidth;
        this.innerRect.right -= borderWidth;
        this.innerRect.bottom -= borderWidth;
        borderPaint = new Paint();
        borderPaint.setAlpha(Paint.ANTI_ALIAS_FLAG);
        borderPaint.setColor(Color.BLACK);
        borderPaint.setStyle(Paint.Style.STROKE);
        borderPaint.setStrokeWidth(borderWidth);
        innerPaint = new Paint();
        innerPaint.setAlpha(Paint.ANTI_ALIAS_FLAG);
        innerPaint.setColor(Color.GREEN);
        innerPaint.setStyle(Paint.Style.FILL);
        setUpPath();

    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        //canvas.drawRoundRect(innerRect, radius, radius, borderPaint);
        //canvas.drawRoundRect(rect, radius, radius,innerPaint);
        canvas.drawPath(path, borderPaint);


    }

    private void setUpPath() {
        path.moveTo(rect.left + 20, rect.top);
        path.lineTo(rect.left + 30, rect.top - 30);
        path.lineTo(rect.left + 40, rect.top);
        path.lineTo(rect.right-10 , rect.top);
        path.addArc(new RectF(rect.right - 20, rect.top, rect.right, rect.top + 20), 270, 90);
        path.lineTo(rect.right , rect.bottom-10);
        path.addArc(new RectF(rect.right - 20, rect.bottom - 20, rect.right, rect.bottom ), 0, 90);
        path.lineTo(rect.left+10 , rect.bottom);
        path.addArc(new RectF(rect.left, rect.bottom - 20, rect.left+20, rect.bottom ), 90, 90);
        path.lineTo(rect.left,rect.top+10);
        path.addArc(new RectF(rect.left,rect.top,rect.left+20,rect.top+20),180,90);
        path.lineTo(rect.left+20,rect.top);
       
        
    }

    @Override
    public void setAlpha(int alpha) {


    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}
